package com.feihong.txgw.adapter.recharge;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.feihong.txgw.R;

import java.util.ArrayList;

public class PhoneRechargeAdapter extends BaseAdapter {
    private int selectPosition = -1;
    private ArrayList<String> mLists;
    private ArrayList<String> mGprsLists;
    private Context mContext;
    private String mType;

    public PhoneRechargeAdapter(Context context, ArrayList<String> lists) {
        this.mLists = lists;
        this.mContext = context;
    }

    public PhoneRechargeAdapter(Context context, ArrayList<String> lists, ArrayList<String> gprsLists) {
        this.mLists = lists;
        this.mGprsLists = gprsLists;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mLists.size();
    }

    @Override
    public String getItem(int position) {
        return mLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = View.inflate(mContext, R.layout.phone_recharge_item_list, null);
        LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll);
        TextView money = (TextView) view.findViewById(R.id.money);
        TextView gprs = (TextView) view.findViewById(R.id.gprs);
        money.setText(mLists.get(position) + "元");
        money.setText(mLists.get(position) + "元"+"\n"+"售价:"+mLists.get(position)+"元");
        if (mGprsLists != null) {
            if (mGprsLists.size() > 0) {
                gprs.setVisibility(View.VISIBLE);
                money.setText("售价:"+mLists.get(position)+"元");
                gprs.setText(mGprsLists.get(position));
            } else {
                gprs.setVisibility(View.GONE);
            }
        }

        //如果当前的position等于传过来点击的position,就去改变他的状态
        if (selectPosition == position) {
            ll.setBackgroundResource(R.drawable.btn_select_package__press_shape);
            money.setTextColor(Color.parseColor("#ffffffff"));
            gprs.setTextColor(Color.parseColor("#ffffffff"));
        } else {
            //其他的恢复原来的状态
            ll.setBackgroundResource(R.drawable.btn_select_package_shape);
            money.setTextColor(mContext.getResources().getColor(R.color.appRed));
            gprs.setTextColor(mContext.getResources().getColor(R.color.appRed));
        }

        return view;
    }

    public void changeState(int position) {
        // 更新状态
        selectPosition = position;
        // 更新adapter
        notifyDataSetChanged();
    }

}
